<script>
 $(document).ready(function(){
    $(".update_version").click(function(){
        var send_id = $(this).attr("id");
        $.ajax({
      	   type: "POST",
      	   url:"<?php echo  base_url();?>model/get_send_for_layout",
      	   data: "send_id="+send_id,
           dataType:'json', 
      	   success: function(msg){          	  
        	   $("#mod_id_notice").html(msg.mod);
        	   $("#category_id_notice").html(msg.category);
        	   $("#version_id").html(msg.version);
        	   $("#count").val(msg.count);
        	   $("#mod_id").val(msg.mod_id);
        	   $("#send_id").val(msg.send_id);
        	   $("#category_id").val(msg.category_id);
        	   $("#company_id").val(msg.company_id);
        	   $("#pre_count").val(msg.count);
        	   $("#pre_version").val(msg.pre_verison);
        	   $("#des").val(msg.des);
        	   $("#pre_codes").val(msg.codes);
  	    	   $("#version_detail").modal();
      	   }
      	});
    })

    $("#submit").click(function(){
    	var send_id = $("#send_id").val();
        var mod_id = $("#mod_id").val();
        var category_id = $("#category_id").val();
        var des = $("#des").val();
        var codes = $("#codes").val();
        var count = $("#count").val();
        var version_id = $("#version_id").val();
        var pre_version = $("#pre_version").val();
        var pre_count = $("#pre_count").val();
        var pre_codes = $("#pre_codes").val();
        var company_id = $("#company_id").val();
        var str = "pre_codes="+pre_codes+"&codes="+codes+"&company_id="+company_id+"&mod_id="+mod_id+"&category_id="+category_id+"&des="+des+"&version_id="+version_id+"&pre_version="+pre_version+"&pre_count="+pre_count+"&count="+count+"&send_id="+send_id;
        $.ajax({
        	   type: "POST",
        	   url:"<?php echo  base_url();?>model/update_send",
        	   data: str, 
        	   success: function(msg){          	  
                    $(".simplemodal-close").click();
                    if(msg=='1'){
                      alert("操作成功!");
                      window.location.reload();
                    }else{
                       alert(msg);
                      }
        	   }
        	});
    })

    $("#mod_id").change(function(){
         var mod_id = $(this).val();
         if(mod_id!=""){
    	 $.ajax({
        	   type: "POST",
        	   url:"<?php echo  base_url();?>model/get_category",
        	   data: "mod_id="+mod_id,
        	   success: function(msg){
            	   $("#category_id").html("");
            	   $("#category_id").html(msg);
            	   $("#send_form").submit();
        	   }
          });   
         }else{
        	 $("#send_form").submit();
         }
     })     

    $("#category_id").change(function(){
         $("#send_form").submit();
     })
     $("#company_id").change(function(){
         $("#send_form").submit();
     })
 })
</script>
<style>
.bs{ background-color:#FF0000;}
</style>
		<div id="center-column">
			<div class="top-bar">
				<a href="<?php echo  base_url();?>model/send_add" class="button">新增</a>
				<h1>Contents</h1>
				<div class="breadcrumbs"><a href="#">首页</a> / <?php echo anchor('model/send','资料发放管理');?></div>
			</div><br />
		  <div class="select-bar">
		  <?php echo form_open('model/send',array('id'=>'send_form'));?> 
		    <label>型号：</label><label><select id="mod_id" name="mod_id">
		                      <option value="">全部型号</option>
		                   <?php foreach($mod as $k=>$val){?>
		                      <option value="<?php echo $val->mod_id;?>" <?php if(isset($mod_id)&&($mod_id==$val->mod_id)){?>selected=true<?php }?>><?php echo $val->name;?></option>
		                   <?php }?>
		                 </select>
		    </label>
		    <label>种类：</label>
		    <label><select id="category_id" name="category_id"><option value="">全部资料种类</option></select></label>
		    <label>发放单位：</label><label><select id="company_id" name="company_id">
		                      <option value="">全部发放单位</option>
		                   <?php foreach($company as $k=>$val){?>
		                      <option value="<?php echo $val->company_id;?>" <?php if(isset($company_id)&&($company_id==$val->company_id)){?>selected=true<?php }?>><?php echo $val->name;?></option>
		                   <?php }?>
		                 </select>
		    </label>
		    <label>
		    <input type="text" name="textfield" />
		    </label>
		    <label>
			<input type="submit" name="Submit" value="搜索" />
			</label>
		  </form>	
		  </div>
			<div class="table">
				
				
				<table class="listing" cellpadding="0" cellspacing="0">
					<tr>
						<th width="17">ID</th>
						<th>型号</th>
						<th>资料种类</th>						
						<th>资料版本</th>
						<th>单据号</th>
						<th>发放单位</th>
						<th>份数</th>						
						<th>时间</th>
						<th>备注</th>	
						<th>发放人员</th>					
						<th >操作</th>
					</tr>
			    <?php foreach($send as $k=>$val):if($val->count!=0){?>		
					<tr <?php if($val->is_update==1){?> class="bs" <?php }?> >
                        <td><?php echo $start;?></td> 
                        <td><?php foreach($mod as $j=>$m){ if($val->mod_id==$m->mod_id){echo $m->name;}}?></td>
                        <td style="text-align:left;padding-left:5px;width:300px;"><?php foreach($category as $j=>$m){ if($val->category_id==$m->category_id){echo $m->name;}}?></td>
                                               
                        <td><?php foreach($version as $j=>$m){ if($val->version_id==$m->version_id){echo $m->name;}}?></td>
                        <td><?php echo $val->codes;?></td>  
                        <td><?php foreach($company as $j=>$m){ if($val->company_id==$m->company_id){echo $m->name;}}?></td>
                        <td><?php echo $val->count;?></td>
                        <td><?php echo date("Y.m.d",$val->createtime);?></td>
                        <td><?php echo $val->des;?></td>
                        <td><?php foreach($admin as $j=>$m){ if($val->user_id==$m->admin_id){echo $m->username;}}?></td>
                        <td><?php echo anchor('model/send_detail/'.$val->send_id,'查看',array('class'=>'send_detail'));?>&nbsp;&nbsp;|&nbsp;&nbsp;<?php echo anchor('model/send_edit/'.$val->send_id,'编辑',array('class'=>'mod_edit'));?>
                            
                        </td>
					</tr>
				<?php $start++;}  endforeach;?>						
				</table>
				<?php echo $page;?>
			</div>
		</div>
	</div>
	<div id="version_detail"><table class="listing form" cellpadding="0" cellspacing="0" style="width:550px;">
	               <input type="hidden" id="pre_count" />
	               <input type="hidden" id="pre_version" />
	               <input type="hidden" id="mod_id" />
	               <input type="hidden" id="send_id" />
	               <input type="hidden" id="category_id" />
	               <input type="hidden" id="company_id" />
	               <input type="hidden" id="pre_codes" />
					<tr>
						<th  colspan="2"  align="center">更新发放版次</th>
					</tr>
					<tr>
						<td style="width:100px;text-align:right;"><strong>型号：</strong></td>
						<td style="text-align:left;">
						<span id="mod_id_notice"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<font color="#FF0000">版次更新状态下，型号，资料种类不可以更改</font></td>
					</tr>
					<tr>
						<td style="width:100px;text-align:right;"><strong>资料种类：</strong></td>
						<td style="text-align:left;"><span id="category_id_notice"></span></td>
					</tr>
					<tr>
						<td style="width:100px;text-align:right;"><strong>资料版本：</strong></td>
						<td style="text-align:left;"><select name="version_id" id="version_id" >					                       
						                    	
						                 </select><span id="version_id_notice"></span></td>
					</tr>
                    <tr class="bg">
						<td style="width:100px;text-align:right;"><strong>发放单据号：</strong></td>
						<td style="text-align:left;"><input type="text" class="text" name="codes" id="codes" value="" /></td>
					</tr>
					<tr class="bg">
						<td style="width:100px;text-align:right;"><strong>发放份数：</strong></td>
						<td style="text-align:left;"><input type="text" class="text" name="count" id="count" value="" /><span id="count_notice"></span></td>
					</tr>
					<tr class="bg">
						<td style="width:100px;text-align:right;"><strong>备注：</strong></td>
						<td style="text-align:left;"><textarea name="des" cols="50" rows="5" id="des"></textarea></td>
					</tr>
					<tr>
						<td colspan="2"><input type="button" value="提交" class="button" id="submit"/></td>			
					</tr>
				</table></div>
	<div id="footer"></div>
</div>

<input type="hidden" id="version_mod_id" value="<?php echo $mod_id;?>"/>
<input type="hidden" id="version_category_id" value="<?php echo $category_id;?>"/>
<input type="hidden" id="version_company_id" value="<?php echo $company_id;?>"/>
</body>
</html>
<script>
  $(document).ready(function(){
	  var mod_id = $("#version_mod_id").val();
	  var category_id = $("#version_category_id").val();
	  var company_id = $("#version_company_id").val();
		 $.ajax({
		  	   type: "POST",
		  	   url:"<?php echo  base_url();?>model/get_category",
		  	   data: "mod_id="+mod_id,
		  	   success: function(msg){
		      	   $("#category_id").html("");
		      	   $("#category_id").html(msg);
			      	 $("select[name=category_id]").val(category_id);
				     $("select[name=company_id]").val(company_id);
		  	   }
		    });
   })
</script>
